<?php
namespace app\admin\controller;
use \think\Controller;
use \think\Request;
use \think\facade\Session;

/*后台登陆入口*/
class Banner extends Base
{  
    /*列表*/
	public function index(Request $request){
		$this->check_session();
        /*左侧导航*/
        $data_get=$request->get()['nav'];
        $data=$this->navleft($data_get);
        $model=new \app\admin\model\Banner();/*调用模型查询*/
        $model_data=$model->get_data();
        $data['data_list']=$model_data;
        $this->assign($data);
	    return $this->fetch();
	}

	    /*新增 或者 修改*/
	public function change(Request $request){
		$this->check_session();
        $data=$request->post();
    	if(empty($data)){
          return $this->fetch();
        }else{
          if(empty($data['alt'])){
            $result=['status'=>'0','msg'=>'请填写alt'];
            return json($result);
          }
          if(empty($data['newname'])){
            $result=['status'=>'0','msg'=>'请上传图片'];
            return json($result);
          }
          $model=new \app\admin\model\Banner();/*调用模型查询*/
          $get=$request->get();
          if(!empty($get['id'])){
            $model_data=$model->update_data($get['id'],$data['alt'],$data['newname'],$data['type']);
          }else{
            $model_data=$model->insert_data($data['alt'],$data['newname'],$data['type']);
          }
          if($model_data==1){
                $result=['status'=>'1','msg'=>'操作成功'];
                return json($result);
           }else{
                $result=['status'=>'0','msg'=>'操作失败系统错误'];
                return json($result);
           }
        }
	}
    
     /*删除*/
    public function del(Request $request){
        $this->check_session();
        $data=$request->post();
        if(empty($data['id'])){
            $result=['status'=>'0','msg'=>'操作有误'];
            return json($result);
        }
        $model=new \app\admin\model\Banner();/*调用模型查询*/
        $model_data=$model->delete_data($data['id']);
        if($model_data!=1){
            $result=['status'=>'0','msg'=>'删除失败'];
            return json($result);
        }else{
            $result=['status'=>'1','msg'=>'删除成功'];
            return json($result);
        }
    }


}	